package com.csguider.auth;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csguider.auth.service.SysRoleService;
import com.csguider.model.system.SysRole;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * @Author <a href="https://github.com/wl2o2o">程序员CSGUIDER</a>
 * @From <a href="https://wl2o2o.github.io">CSGUIDER博客</a>
 * @CreateTime 2024/4/27
 */

@SpringBootTest
public class QueryWrapperTestDemo1 {

    @Autowired
    private SysRoleService sysRoleService;

    // 查询所有
    @Test
    public void query() {
        QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", 0);
        List<SysRole> list = sysRoleService.list(wrapper);
        System.out.println(list);
    }

    // 数据库字段（is_deleted）容易拼错且不好记忆，于是可通过正则查询
    @Test
    public void query2() {
        LambdaQueryWrapper<SysRole> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysRole::getIsDeleted, 1);
        List<SysRole> list = sysRoleService.list(lambdaQueryWrapper);
        System.out.println(list);
    }


}
